// pages/indexdetail/indexdetail.js
// import Dialog from 'path/to/@vant/weapp/dist/dialog/dialog';
const app = getApp()
Page({
// "人民英雄纪念碑"
// "杭州西湖"
	/**
	 * 页面的初始数据
	 */
	data: {
		data:{},
		shebei:'',
		message:'',
		autosize:{
			maxHeight:100,
			minHeight:50
		},
		showDisclaimers:false,
		showDisclaimers1:false,
	},
	GoNavigation(){
		
		let latitude = this.data.data.latitude;
		let longitude = this.data.data.longitude;
		let lastname = this.data.data.lastname;

		wx.openLocation({
		     latitude:Number(latitude),
		     longitude:Number(longitude),
			 name:lastname,
		   })
	},
	GoNavigationt(){
		
		let latitude = this.data.data.latitude;
		let longitude = this.data.data.longitude;
		let lastname = this.data.data.lastname;
		let plugin = requirePlugin('routePlan');
		let key = 'YBCBZ-WC4CU-P4EVZ-25TQK-UZAKE-XQBKR';  //使用在腾讯位置服务申请的key
		let referer = '75带班';   //调用插件的app的名称
		let endPoint = JSON.stringify({  //终点
		  'name': lastname,
		  'latitude': latitude,
		  'longitude': longitude,
		  'navigation':1
		});
		wx.navigateTo({
		  url: 'plugin://routePlan/index?key=' + key + '&referer=' + referer + '&endPoint=' + endPoint
		});

	},
	onheaderClickLeft() {
		wx.navigateBack({})
	},
	Disclaimers(){
		this.setData({showDisclaimers:true})
	},
	CloseDisclaimers(){
		this.setData({showDisclaimers:false})
	},
	confiryDisclaimers(){
		this.setData({showDisclaimers:false})
	},
	Disclaimers1(){
		this.setData({showDisclaimers1:true})
	},
	CloseDisclaimers1(){
		this.setData({showDisclaimers1:false})
	},
	confiryDisclaimers1(){
		this.setData({showDisclaimers1:false})
	},
	handleBackIndex(){
		wx.navigateBack({})
	},
	handleBackReportdetail(){
		if(!app.globalData.hasUserInfo){
			app.handleLogin();
			return false;
		}
		wx.navigateTo({
			url: '../reportedit/reportedit',
		});
	},
	GetData(id){
		var param = {};
		param['id'] = id;
		if(app.globalData.hasUserInfo){
			const token = wx.getStorageSync('token');
			param['token'] = token;
		}
		wx.showLoading({ //期间为了显示效果可以添加一个过度的弹出框提示“加载中”
			title: '加载中',
			icon: 'loading',
		});
		wx.request({
			url: 'https://www.grabinter.com/Works/showworks',
			method: 'POST',
			data:param,
			header: {
				"Content-Type": 'application/x-www-form-urlencoded'
			},
			success: json => {
				const data = json.data.data;
				wx.hideLoading();
				if(json.data.error && token){
					app.handleLogin();
					return false;
				}
				if(parseInt(data.sid)>0){
					var shebeitext = '';
					for(var i in app.globalData.shebei){
						for(var x in app.globalData.shebei[i].children){
							const itgem = app.globalData.shebei[i].children[x];
							if(itgem.sid == data.sid){
								shebeitext = itgem.text
							}
						}
					}
					this.setData({
						shebei:shebeitext
					})
				}
				this.setData({
					data:data
				})
			}
		});
	},
	handlePhone(event){
		var self = this;
		var id = this.data.data.id;
		if(!app.globalData.hasUserInfo){
			app.handleLogin();
			return false;
		};
		if(parseInt(this.data.data.status)>0){
			wx.showModal({
				title: '温馨提示',
				content: '是否拨打该招聘电话？',
				success (res) {
					if (res.confirm) {
						wx.makePhoneCall({
							phoneNumber: self.data.data.phone
						});
					}else if (res.cancel) {
					}
				}
			});
			
			return false;
		};
		
		if(!id){
			wx.showToast({
				title: '参数错误',
				icon: 'error',
				duration: 2000,
			});
			return false;
		}
		var that = this;
		wx.showModal({
			title: '温馨提示',
			content: '是否确认支付？',
			success (res) {
				if (res.confirm) {
					//发起预支付，获取所需参数
					wx.request({
						url: 'https://www.grabinter.com/Pay/index/',   //请求地址
						method: 'POST',
						header: {
							"Content-Type": 'application/x-www-form-urlencoded'
						},
						data: {
							id: id,
							token: wx.getStorageSync('token'),
						},
						success:res => {
							var data = res.data;
								//发起微信支付
								wx.requestPayment({
									timeStamp: data.timeStamp,
									nonceStr: data.nonceStr,
									package: data.package,
									signType: data.signType,
									paySign: data.paySign,
									success() {
					　　　　　　　　		wx.showToast({
											title: '支付成功',
											icon: 'success',
											duration: 2000,
										});
										self.setData({
											'data.status':1
										});
									},
									fail() {
										wx.showToast({
											title: '支付失败',
											icon: 'error',
											duration: 2000,
										});
									}
								})
						
						}
					});
				}else if (res.cancel) {
				}
			}
		});
		
		
	},
	watchUserInfo(val){
		if(val){
			this.GetData(this.data.data.id);
		}
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		if(!parseInt(options.id)){
			wx.showToast({
				title: '参数错误',
				icon: 'error',
				duration: 2000,
			});
			setTimeout(()=>{
				wx.navigateBack({})
			},2000)
			return false;
		}
		this.GetData(options.id);
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function() {
		app.watchHasUserInfo(this.watchUserInfo)
	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {

	}
})
